package com.dstz.demo.rest.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dstz.base.rest.BaseController;
import com.dstz.demo.core.manager.InvestigatePresentationManager;
import com.dstz.demo.core.model.Investigate;
import com.dstz.demo.core.model.InvestigatePresentation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys/InvestigatePresentation")
public class InvestigatePresentationController extends BaseController<InvestigatePresentation> {
    @Resource
    InvestigatePresentationManager investigatePresentationManager;
    @Override
    protected String getModelDesc() {
        return null;
    }
    @PostMapping("/findinfo/{id}")
    public List<InvestigatePresentation> findinfo(@PathVariable String id){
        List<InvestigatePresentation> list= investigatePresentationManager.findlist(id);
        return list;
    }
    @PostMapping("/byid/{id}")
    public List<List<Map>> Byid(@PathVariable String id){
        InvestigatePresentation investigatePresentation=investigatePresentationManager.ById(id);
        String name= investigatePresentation.getJsry()+"&"+investigatePresentation.getGcgmry()+"&"+investigatePresentation.getSbry()+"&"+investigatePresentation.getGlry()+"&"+investigatePresentation.getJyry();
        List<List<Map>> map=new ArrayList<>();
        List<Map> jsonToList = JSONArray.parseArray(investigatePresentation.getJsry(),Map.class);
        List<Map> jsonToList2 = JSONArray.parseArray(investigatePresentation.getGcgmry(),Map.class);
        List<Map> jsonToList3 = JSONArray.parseArray(investigatePresentation.getSbry(),Map.class);
        List<Map> jsonToList4 = JSONArray.parseArray(investigatePresentation.getGlry(),Map.class);
        List<Map> jsonToList5 = JSONArray.parseArray(investigatePresentation.getJyry(),Map.class);
        map.add(jsonToList);
        map.add(jsonToList2);
        map.add(jsonToList3);
        map.add(jsonToList4);
        map.add(jsonToList5);
        //        if(investigatePresentation.getJsry()==null){
//            investigate.setId("");
//            investigate.setName("");
//        }else{
//            System.out.println(investigatePresentation.getJsry());
//            JSONObject jsonObject = JSONObject.parseObject(investigatePresentation.getJsry());
//
//            investigate.setId(jsonObject.getString("id"));
//            investigate.setId(jsonObject.getString("name"));
//        }
//        if(investigatePresentation.getGcgmry()==null){
//            investigate.setGcgmry("");
//        }else{
//            investigate.setGcgmry(investigatePresentation.getGcgmry());
//        }
//        if(investigatePresentation.getSbry()==null){
//            investigate.setSbry("");
//        }else{
//            investigate.setSbry(investigatePresentation.getSbry());
//        }
//        if(investigatePresentation.getGlry()==null){
//            investigate.setGlry("");
//        }else{
//            investigate.setGlry(investigatePresentation.getGlry());
//        }
//        if(investigatePresentation.getJyry()==null){
//            investigate.setJyry("");
//        }else{
//            investigate.setJyry(investigatePresentation.getJyry());
//        }
        return map;
    }
}
